package com.gqb.action;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.util.ServletContextAware;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Action;
public class FileDownload implements Action ,ServletContextAware ,ServletResponseAware{
	
	private String fileName;
	private final static String UPLOADPATH = "d:/upload/";
	private ServletContext servletContext;
	private HttpServletResponse response;
	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	
	public InputStream getDownloadFile() throws FileNotFoundException{
		String path = UPLOADPATH + fileName;
		System.out.println("path>>"+path);
		InputStream in = new FileInputStream(path);
		response.setContentType("application/pdf");
		
		
		return in;
		
	}
	
	public String execute() throws Exception {   
		System.out.println("fileName>>"+fileName);
        return Action.SUCCESS;   
    }

	@Override
	public void setServletContext(ServletContext arg0) {
		this.servletContext=arg0;
	}

	@Override
	public void setServletResponse(HttpServletResponse arg0) {
		this.response=arg0;
	}   
	
}
